home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 23 / Amiga Format AFCD23 (Feb 1998, Issue 107).iso / -seriously_amiga- / shareware / programming / e / easyplugins / source / register.e < prev    next >
Text File  |  1997-12-06  |  8KB  |  321 lines

  1. /*
  2. **
  3. ** register PLUGIN
  4. **
  5. ** Copyright: Ralph Wermke of Digital Innovations
  6. ** EMail    : wermke@gryps1.rz.uni-greifswald.de
  7. ** WWW      : http://www.user.fh-stralsund.de/~rwermke/di.html
  8. **
  9. ** Version  : 1.1.2
  10. ** Date     : 15-Nov-1997
  11. **
  12. ** ProgramID: 0001
  13. **
  14. ** History:
  15. **    03-Sep-1997:          V1.0 beta
  16. **       - first beta release
  17. **    02-Nov-1997:          V1.1
  18. **       - some minor changes
  19. **       - special values for ActivePage (FIRST,LAST,NEXT,PREV)
  20. **         now also usable on init
  21. **    05-Nov-1997:          V1.1.1
  22. **       - enforcer hits removed
  23. **    15-Nov-1997:          V1.1.2
  24. **       - object name changed to register_plugin
  25. **
  26. */
  27.  
  28. OPT OSVERSION=37
  29. OPT PREPROCESS
  30. OPT MODULE
  31.  
  32. ->#define lite_version
  33.  
  34. #ifdef lite_version
  35.    MODULE 'tools/EasyGUI_lite'
  36. #endif
  37.  
  38. #ifndef lite_version
  39.    MODULE 'tools/EasyGUI'
  40. #endif
  41.  
  42. MODULE 'tools/textlen','tools/ghost',
  43.        'graphics/text','graphics/rastport',
  44.        'intuition/intuition','intuition/screens',
  45.        'utility/tagitem','utility','utility/hooks',
  46.        'amigalib/boopsi'
  47.  
  48.  
  49. EXPORT OBJECT register_plugin OF plugin
  50. PRIVATE
  51.    titles      : PTR TO LONG
  52.    current
  53. ->   oldvalue
  54.    hook        : PTR TO hook
  55.    disabled
  56.    max
  57.    mousex
  58.    mousey
  59.  
  60.    shinepen
  61.    shadowpen
  62.  
  63.    ta          : PTR TO textattr
  64. ENDOBJECT
  65.  
  66. EXPORT CONST PLV_Register_ActivePage_First =  0,
  67.              PLV_Register_ActivePage_Last  = -1,
  68.              PLV_Register_ActivePage_Next  = -2,
  69.              PLV_Register_ActivePage_Prev  = -3
  70.  
  71. -> TAG_USER  | PROG_ID<<16 | TAG_VALUE
  72. -> $80000000 |   $0001<<16 | 0...
  73.  
  74. EXPORT ENUM  PLA_Register_Disabled=$80010001,
  75.              PLA_Register_ActivePage,
  76.              PLA_Register_Titles,
  77.              PLA_Register_ActionHook
  78.  
  79.  
  80.  
  81. ->>> register::register (Constructor)
  82. PROC register(tags:PTR TO tagitem) OF register_plugin
  83.  
  84.    self.gh:=0     -> because it's not initialized
  85.                   -> I need it to avoid drawing before gui is open
  86.    self.hook:=NIL
  87.  
  88.    IF utilitybase:=OpenLibrary('utility.library', 37)
  89.  
  90.       self.disabled  :=GetTagData(PLA_Register_Disabled, FALSE, tags)
  91.       self.titles    :=GetTagData(PLA_Register_Titles, NIL, tags)
  92.  
  93.       IF self.titles<>NIL
  94.          IF ListLen(self.titles)>0
  95.             self.max:=ListLen(self.titles)-1
  96.          ELSE
  97.             Raise("TITL")
  98.          ENDIF
  99.       ELSE
  100.          Raise("TITL")
  101.       ENDIF
  102.  
  103.       self.current:=0
  104.       self.set(PLA_Register_ActivePage, GetTagData(PLA_Register_ActivePage, 0,tags))
  105.       self.hook:=GetTagData(PLA_Register_ActionHook, NIL, tags)
  106.  
  107.       self.shinepen  :=2
  108.       self.shadowpen :=1
  109.  
  110.       CloseLibrary(utilitybase)
  111.    ELSE
  112.       Raise("UTIL")
  113.    ENDIF
  114.  
  115. ENDPROC
  116. -><<
  117.  
  118. PROC will_resize() OF register_plugin IS RESIZEX
  119.  
  120. ->>> register::min_size
  121. PROC min_size(ta:PTR TO textattr, fh) OF register_plugin
  122. DEF x=0, i
  123.  
  124.    FOR i:=0 TO self.max DO x:=Max(x, textlen(ListItem(self.titles, i), ta))
  125.    /* 10 is minimum width without text */
  126.    x:=(x+10)*(self.max+1)
  127.  
  128. ENDPROC x,fh+6
  129. -><<
  130.  
  131. ->>> register::render
  132. PROC render(ta:PTR TO textattr, x, y, xs, ys, win:PTR TO window) OF register_plugin
  133. DEF oldwin, dri:PTR TO drawinfo
  134.  
  135.    self.ta :=ta
  136.  
  137.    IF dri:=GetScreenDrawInfo(win.wscreen)
  138.       self.shinepen :=dri.pens[SHINEPEN]
  139.       self.shadowpen:=dri.pens[SHADOWPEN]
  140.       FreeScreenDrawInfo(win.wscreen, dri)
  141.    ENDIF
  142.  
  143.    oldwin:=self.gh.wnd
  144.    self.gh.wnd:=win
  145.    self.draw(TRUE)            /* full redraw */
  146.    self.gh.wnd:=oldwin
  147.  
  148. ENDPROC
  149. -><<
  150.  
  151. ->>> register::draw
  152. /* draws the full register */
  153. PROC draw(redraw=FALSE) OF register_plugin
  154. DEF i, labelnum, x, y, xs, ys, rp
  155.  
  156.    IF self.gh=0 THEN RETURN      /* ignore draw before gui is open */
  157.    IF self.gh.wnd=0 THEN RETURN  /* ignore draw when window is closed */
  158.  
  159.    rp:=self.gh.wnd.rport
  160.    x :=self.x
  161.    y :=self.y
  162.    xs:=self.xs
  163.    ys:=self.ys
  164.  
  165.    labelnum:=self.max+1
  166.  
  167.    IF Not(redraw)
  168.       /* clear full area */
  169.       SetAPen(rp, 0)
  170.       RectFill(rp, x, y, x+xs, y+ys)
  171.    ENDIF
  172.  
  173.    FOR i:=0 TO labelnum-1
  174.       self.drawRegister(x+(xs/labelnum*i), y, (xs/labelnum), ys, ListItem(self.titles, i), IF i<>self.current THEN FALSE ELSE TRUE)
  175.    ENDFOR
  176.  
  177.    IF self.disabled THEN ghost(self.gh.wnd, x, y, xs, ys)
  178.  
  179. ENDPROC
  180. -><<
  181.  
  182. ->>> register::drawRegister
  183. /* draws a single label */
  184. PROC drawRegister(x, y, xs, ys, text, active=TRUE) OF register_plugin
  185. DEF rp:REG, xxs:REG, yys:REG, itext, itext2, textx, texty, ta:REG PTR TO textattr
  186.  
  187.    rp:=self.gh.wnd.rport
  188.    ta:=self.ta
  189.  
  190.    IF active=FALSE
  191.       y:=y+2; ys:=ys-2
  192.    ENDIF
  193.  
  194.    xxs:=x+xs; yys:=y+ys
  195.  
  196.    SetAPen(rp, self.shinepen)
  197.    RectFill(rp, x+1, y+3, x+1, yys-1)
  198.    RectFill(rp, x+4, y, xxs-4, y)
  199.    WritePixel(rp, x+2, y+2)
  200.    WritePixel(rp, x+3, y+1)
  201.    SetAPen(rp, self.shadowpen)
  202.    RectFill(rp, xxs-1, y+3, xxs-1, yys-1)
  203.    WritePixel(rp, xxs-2, y+2)
  204.    WritePixel(rp, xxs-3, y+1)
  205.  
  206.    IF active=FALSE
  207.       SetAPen(rp, self.shinepen)
  208.       RectFill(rp, x, yys, xxs, yys)
  209.    ENDIF
  210.  
  211.    IF text
  212.       textx :=x+((xs-textlen(text, ta))/2)+1
  213.       texty :=y+((ys-ta.ysize)/2)+1
  214.       itext :=[self.shadowpen, 0, RP_JAM1, textx, texty, ta, text, NIL]:intuitext
  215.       itext2:=[self.shinepen, 0, RP_JAM1, textx+1, texty+1, ta, text, itext]:intuitext
  216.       PrintIText(rp, IF active THEN itext2 ELSE itext, 0, 0)
  217.    ENDIF
  218.  
  219. ENDPROC
  220. -><<
  221.  
  222. ->>> register::message_test
  223. PROC message_test(imsg:PTR TO intuimessage, win:PTR TO window) OF register_plugin
  224.  
  225.    IF self.disabled THEN RETURN FALSE
  226.  
  227.    IF (imsg.class=IDCMP_MOUSEBUTTONS) AND (imsg.code=SELECTUP)
  228.       /* store hit point */
  229.       self.mousex:=win.mousex
  230.       self.mousey:=win.mousey
  231.       /* check boundaries */
  232.       IF (self.mousex>=self.x) AND (self.mousex<=(self.x+self.xs)) AND (self.mousey>=(self.y+2)) AND (self.mousey<=(self.y+self.ys))
  233.          RETURN TRUE
  234.       ENDIF
  235.    ENDIF
  236.  
  237. ENDPROC FALSE
  238. -><<
  239.  
  240. ->>> register::message_action
  241. PROC message_action(class, qual, code, win:PTR TO window) OF register_plugin
  242. DEF i, labelnum:REG, left, right, break=FALSE
  243.  
  244.    labelnum:=self.max+1
  245.  
  246.    FOR i:=0 TO labelnum-1
  247.       IF i<>self.current                     /* ignore current label */
  248.          left  :=self.x+(self.xs/labelnum*i)
  249.          right :=left+(self.xs/labelnum)
  250.          IF (self.mousex>left) AND (self.mousex<right) THEN break:=TRUE
  251.       ENDIF
  252.       EXIT break
  253.    ENDFOR
  254.  
  255.    IF break
  256.       self.current:=i
  257.       self.draw()                            /* update */
  258.       IF self.hook<>NIL THEN callHookA(self.hook, self, self.current)
  259.       RETURN TRUE
  260.    ENDIF
  261.  
  262. ENDPROC FALSE
  263. -><<
  264.  
  265. ->>> register::set
  266. PROC set(attr, value) OF register_plugin
  267.  
  268.    SELECT attr
  269.       CASE PLA_Register_Disabled
  270.          IF value
  271.             self.disabled:=TRUE
  272.             IF self.gh<>0           /* ignore draw before gui is open */
  273.                IF self.gh.wnd<>0    /* ignore draw when window is closed */
  274.                   IF self.gh.wnd THEN ghost(self.gh.wnd, self.x, self.y, self.xs, self.ys)
  275.                ENDIF
  276.             ENDIF
  277.          ELSE
  278.             self.disabled:=FALSE
  279.             self.draw()             /* update */
  280.          ENDIF
  281.       CASE PLA_Register_ActivePage
  282.          IF (value>=0) AND (value<=self.max)
  283.             self.current:=value
  284.          ELSE
  285.             SELECT value
  286.                CASE PLV_Register_ActivePage_First
  287.                   self.current:=0
  288.                CASE PLV_Register_ActivePage_Last
  289.                   self.current:=self.max
  290.                CASE PLV_Register_ActivePage_Next
  291.                   self.current:=self.current+1
  292.                   IF self.current>self.max THEN self.current:=0
  293.                CASE PLV_Register_ActivePage_Prev
  294.                   self.current:=self.current-1
  295.                   IF self.current<0 THEN self.current:=self.max
  296.                DEFAULT
  297.                   self.current:=0
  298.             ENDSELECT
  299.          ENDIF
  300.          self.draw()       /* update */
  301.          -> call hook only if the gui is initialized
  302.          IF (self.hook<>NIL) AND (self.gh) THEN callHookA(self.hook, self, self.current)
  303.    ENDSELECT
  304.  
  305. ENDPROC
  306. -><<
  307.  
  308. ->>> register::get
  309. PROC get(attr) OF register_plugin
  310.  
  311.    SELECT attr
  312.       CASE PLA_Register_Disabled
  313.          RETURN self.disabled, TRUE
  314.       CASE PLA_Register_ActivePage
  315.          RETURN self.current, TRUE
  316.    ENDSELECT
  317.  
  318. ENDPROC -1, FALSE
  319. -><<
  320.  
  321.